
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
//import java.sql.SQLOutput;

public class Text3 {
    public static void main(String[] args) throws SQLException {
        //1.创建并初始化数据源
        DataSource datasoure = new MysqlDataSource();
        ((MysqlDataSource)datasoure).setUrl("jdbc:mysql://127.0.0.1:3306/text?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)datasoure).setUser("root");
        ((MysqlDataSource)datasoure).setPassword("Aa20021203X");
        //2.和服务器建立连接
        Connection connection = datasoure.getConnection();
        //3.构造SQL语句
        String sql = "update student set id = 1 where id = 2";
        PreparedStatement statement = connection.prepareStatement(sql);//预编译SQL
        //4.执行SQL语句
        int ret = statement.executeUpdate();
        System.out.println(ret);
        //5.释放必要的资源
        statement.close();
        connection.close();
    }
}


